<template>
  <div class="screen-sidebar">
    <el-tabs>
      <el-tab-pane label="组件库">
        <div class="component-categories">
          <el-tabs tab-position="left" class="category-tabs">
            <el-tab-pane v-for="category in componentCategories" :key="category.type" :label="category.name">
              <div class="component-list">
                <div v-for="item in category.components" 
                     :key="item.type" 
                     class="component-item"
                     draggable="true"
                     @dragstart="handleDragStart(item)"
                >
                  <div class="component-content">
                    <div class="component-icon">
                      <el-icon>
                        <component :is="iconMap[item.icon]" />
                      </el-icon>
                    </div>
                    <div class="component-info">
                      <span class="component-name">{{ item.name }}</span>
                      <span class="component-desc">{{ item.description }}</span>
                    </div>
                  </div>
                </div>
              </div>
            </el-tab-pane>
          </el-tabs>
        </div>
      </el-tab-pane>
      <el-tab-pane label="图层">
        <div class="layer-list">
          <el-empty v-if="!layers?.length" description="暂无图层" />
          <div v-else class="layer-tree">
            <div v-for="layer in layers" :key="layer.id" class="layer-item">
              <div class="layer-content">
                <el-icon><component :is="layer.icon" /></el-icon>
                <span class="layer-name">{{ layer.name }}</span>
                <div class="layer-actions">
                  <el-tooltip content="显示/隐藏" placement="top">
                    <el-icon @click="toggleLayerVisible(layer)">
                      <component :is="layer.visible ? 'View' : 'Hide'" />
                    </el-icon>
                  </el-tooltip>
                  <el-tooltip content="删除" placement="top">
                    <el-icon @click="removeLayer(layer)"><Delete /></el-icon>
                  </el-tooltip>
                </div>
              </div>
            </div>
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<style scoped>
.screen-sidebar {
  width: 260px;
  background: #1d2537;
  border-right: 1px solid #2a3555;
  flex-shrink: 0;
  height: 100%;
}

.component-categories {
  height: calc(100vh - 140px);
  overflow: hidden;
}

.category-tabs {
  height: 100%;
}

.component-list {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: calc(100vh - 180px);
}

.component-item {
  position: relative;
  background: #2a3555;
  border-radius: 4px;
  padding: 12px;
  cursor: move;
  transition: all 0.3s;
}

.component-item:hover {
  background: #3a4565;
}

.component-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.component-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  flex-shrink: 0;
}

.component-icon .el-icon {
  font-size: 20px;
  color: #fff;
}

.component-info {
  flex: 1;
  min-width: 0;
}

.component-name {
  display: block;
  font-size: 14px;
  color: #fff;
  margin-bottom: 4px;
}

.component-desc {
  display: block;
  font-size: 12px;
  color: #999;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

:deep(.el-tabs) {
  height: 100%;
  --el-tabs-header-background-color: transparent;
  --el-text-color-primary: #fff;
  --el-border-color: #2a3555;
}

:deep(.el-tabs__content) {
  height: calc(100% - 40px);
  overflow: hidden;
}

:deep(.el-tab-pane) {
  height: 100%;
}

:deep(.el-tabs__nav) {
  border-color: #2a3555;
}

:deep(.el-tabs__item) {
  color: #999;
}

:deep(.el-tabs__item.is-active) {
  color: #fff;
}

:deep(.el-tabs__active-bar) {
  background-color: #409EFF;
}

/* 滚动条样式 */
.component-list::-webkit-scrollbar {
  width: 6px;
}

.component-list::-webkit-scrollbar-thumb {
  background: #3d4565;
  border-radius: 3px;
}

.component-list::-webkit-scrollbar-track {
  background: #1d2537;
}

/* 图层列表样式 */
.layer-list {
  padding: 12px;
  height: calc(100vh - 140px);
  overflow-y: auto;
}

.layer-item {
  margin-bottom: 8px;
  background: #2a3555;
  border-radius: 4px;
  padding: 8px 12px;
}

.layer-content {
  display: flex;
  align-items: center;
  gap: 8px;
}

.layer-name {
  flex: 1;
  font-size: 14px;
  color: #fff;
}

.layer-actions {
  display: flex;
  gap: 8px;
  color: #999;
}

.layer-actions .el-icon {
  cursor: pointer;
}

.layer-actions .el-icon:hover {
  color: #fff;
}
</style> 